﻿@page "/acrs/forms/{id}"
@layout SimpleIdServer.IdServer.Website.Shared.MainLayout
@attribute [Authorize("Authenticated")]
@using Fluxor.Blazor.Web.Components
@using FormBuilder.Helpers
@using SimpleIdServer.IdServer.Website.Resources
@using SimpleIdServer.IdServer.Website.Shared.Common
@using SimpleIdServer.IdServer.Website.Stores.FormStore
@using SimpleIdServer.IdServer.Website.Stores.AcrsStore
@using FormBuilder.Components.Form
@using FormBuilder.Components
@using FormBuilder.Models.Layout
@using FormBuilder.Models
@using SimpleIdServer.IdServer.Website.Stores.TemplateStore
@inject IState<FormState> formState
@inject IDispatcher dispatcher
@inject IUrlHelper urlHelper
@inherits FluxorComponent

<SidAuthorizeView Roles=@("/acrs/manage,/acrs/view")>
    <Authorized>
        <RadzenBreadCrumb>
            <RadzenBreadCrumbItem Path="@urlHelper.GetUrl("/acrs/forms")" Text="@Global.Forms" />
            <RadzenBreadCrumbItem Text="@formState.Value.Form?.Name" />
        </RadzenBreadCrumb>
        <SidAuthorizeView Roles="/acrs/manage">
            <Authorized>
                <FormEditorComponent Id="@id" CanSave=true></FormEditorComponent>
            </Authorized>
            <NotAuthorized>
                <FormEditorComponent Id="@id" CanSave=false></FormEditorComponent>
            </NotAuthorized>
        </SidAuthorizeView>
    </Authorized>
    <NotAuthorized>
        @Global.NotAuthorized
    </NotAuthorized>
</SidAuthorizeView>

@code {
    [Parameter]
    public string id { get; set; }

    protected override void OnParametersSet()
    {
        base.OnParametersSet();
        if(!string.IsNullOrWhiteSpace(id))
        {
            dispatcher.Dispatch(new GetAllAuthenticationWorkflowLayoutsAction());
            dispatcher.Dispatch(new GetActiveTemplateAction());
            dispatcher.Dispatch(new GetAllTemplatesAction());
        }
    }
}
